home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIMETA.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  275 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include <commctrl.h>
  27. #include "globals.h"            // prototypes specific to this application
  28. #include "resource.h"
  29.  
  30. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  33. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  34.  
  35. // About dialog message table definition.
  36. MSD rgmsdAbout[] =
  37. {
  38.     {WM_COMMAND,    MsgAboutCommand},
  39.     {WM_INITDIALOG, MsgAboutInit}
  40. };
  41.  
  42. MSDI msdiAbout =
  43. {
  44.     sizeof(rgmsdAbout) / sizeof(MSD),
  45.     rgmsdAbout,
  46.     edwpNone
  47. };
  48.  
  49. // About dialog command table definition.
  50. CMD rgcmdAbout[] =
  51. {
  52.     {IDOK,     CmdAboutDone},
  53.     {IDCANCEL, CmdAboutDone}
  54. };
  55.  
  56. CMDI cmdiAbout =
  57. {
  58.     sizeof(rgcmdAbout) / sizeof(CMD),
  59.     rgcmdAbout,
  60.     edwpNone
  61. };
  62.  
  63. // Module specific "globals"  Used when a variable needs to be
  64. // accessed in more than on handler function.
  65.  
  66. HFONT hFontCopyright;
  67.  
  68. //
  69. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  70. //
  71. //  PURPOSE: Displays the "About" dialog box
  72. //
  73. //  PARAMETERS:
  74. //    hwnd      - Window handle
  75. //    wCommand  - IDM_ABOUT (unused)
  76. //    wNotify   - Notification number (unused)
  77. //    hwndCtrl  - NULL (unused)
  78. //
  79. //  RETURN VALUE:
  80. //
  81. //    Always returns 0 - Message handled
  82. //
  83. //  COMMENTS:
  84. //    To process the IDM_ABOUT message, call DialogBox() to display the
  85. //    about dialog box.
  86.  
  87. #pragma argsused
  88. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  89. {
  90.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  91.     return 0;
  92. }
  93.  
  94.  
  95. //
  96. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  97. //
  98. //  PURPOSE:  Processes messages for "About" dialog box.
  99. //
  100. //  PARAMETERS:
  101. //    hdlg - window handle of the dialog box
  102. //    wMessage - type of message
  103. //    wparam - message-specific information
  104. //    lparam - message-specific information
  105. //
  106. //  RETURN VALUE:
  107. //    TRUE - message handled
  108. //    FALSE - message not handled
  109. //
  110. //  COMMENTS:
  111. //
  112. //     Display version information from the version section of the
  113. //     application resource.
  114. //
  115. //     Wait for user to click on "Ok" button, then close the dialog box.
  116. //
  117.  
  118. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  119. {
  120.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  121. }
  122.  
  123.  
  124. //
  125. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  126. //
  127. //  PURPOSE: To initialize the about box with version info from resources.
  128. //
  129. //  PARAMETERS:
  130. //    hwnd - The window handing the message.
  131. //    uMessage - The message number. (unused).
  132. //    wparam - Message specific data (unused).
  133. //    lparam - Message specific data (unused).
  134. //
  135. //  RETURN VALUE:
  136. //    Always returns 0 - message handled.
  137. //
  138. //  COMMENTS:
  139. //    Uses the version apis to retrieve version information for
  140. //    each of the static text boxes in the about box.
  141. //
  142.  
  143. #pragma argsused
  144. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  145. {
  146.     #define POINTSIZE 8
  147.  
  148.     char  szFullPath[256];
  149.     DWORD dwVerHnd;
  150.     DWORD dwVerInfoSize;
  151.     HDC   hDC;
  152.     int   iLogPixelsY, iPointSize;
  153.  
  154.     // Center the dialog over the application window
  155.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  156.  
  157.      // Set the copyright font to something smaller than default
  158.     hDC = GetDC(hdlg);
  159.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  160.     ReleaseDC(hdlg, hDC);
  161.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  162.     iPointSize *= -1;
  163.  
  164.     hFontCopyright = CreateFont(iPointSize,
  165.                                 0, 0, 0,
  166.                                 FW_BOLD,
  167.                                 0, 0, 0, 0,
  168.                                 0, 0, 0, 0,
  169.                                           "Arial");
  170.  
  171.     SendDlgItemMessage(hdlg, 
  172.                        IDD_VERLAST, 
  173.                        WM_SETFONT, 
  174.                        (WPARAM)hFontCopyright,
  175.                        0L);
  176.  
  177.     // Get version information from the application
  178.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  179.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  180.     if (dwVerInfoSize)
  181.      {
  182.         // If we were able to get the information, process it:
  183.         HANDLE  hMem;
  184.         LPVOID  lpvMem;
  185.         char    szGetName[256];
  186.         int     cchRoot;
  187.         int     i;
  188.  
  189.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  190.         lpvMem = GlobalLock(hMem);
  191.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  192.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  193.           cchRoot = lstrlen(szGetName);
  194.  
  195.         // Walk through the dialog items that we want to replace:
  196.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  197.         {
  198.             BOOL  fRet;
  199.             UINT  cchVer = 0;
  200.             LPSTR lszVer = NULL;
  201.             char  szResult[256];
  202.  
  203.             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  204.                 lstrcpy(&szGetName[cchRoot], szResult);
  205.                 fRet = VerQueryValue(lpvMem, szGetName, (LPVOID) &lszVer, &cchVer);
  206.  
  207.             if (fRet && cchVer && lszVer)
  208.             {
  209.                 // Replace dialog item text with version info
  210.                 lstrcpy(szResult, lszVer);
  211.                 SetDlgItemText(hdlg, i, szResult);
  212.             }
  213.         }
  214.         GlobalUnlock(hMem);
  215.         GlobalFree(hMem);
  216.     }
  217.      return TRUE;
  218. }
  219.  
  220. //
  221. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  222. //
  223. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  224. //
  225. //  PARAMETERS:
  226. //    hwnd - The window handing the message.
  227. //    uMessage - The message number. (unused).
  228. //    wparam - Message specific data (unused).
  229. //    lparam - Message specific data (unused).
  230. //
  231. //  RETURN VALUE:
  232. //    Always returns 0 - message handled.
  233. //
  234. //  COMMENTS:
  235. //    Uses this DipsCommand function defined in wndproc.c combined
  236. //    with the cmdiAbout structure defined in this file to handle
  237. //    the command messages for the about dialog box.
  238. //
  239.  
  240. #pragma argsused
  241. LRESULT MsgAboutCommand(HWND   hwnd,
  242.                                 UINT   uMessage,
  243.                                 WPARAM wparam,
  244.                                 LPARAM lparam)
  245. {
  246.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  247. }
  248.  
  249. //
  250. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  251. //
  252. //  PURPOSE: Free the about box and related data.
  253. //
  254. //  PARAMETERS:
  255. //    hwnd - The window handling the command.
  256. //    wCommand - The command to be handled (unused).
  257. //    hwndCtrl - NULL (unused).
  258. //
  259. //  RETURN VALUE:
  260. //    Always returns TRUE.
  261. //
  262. //  COMMENTS:
  263. //    Calls EndDialog to finish the dialog session.
  264. //
  265.  
  266. #pragma argsused
  267. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  268. {
  269.      if (hFontCopyright)
  270.          DeleteObject(hFontCopyright);
  271.  
  272.     EndDialog(hdlg, TRUE);          // Exit the dialog
  273.     return TRUE;
  274. }
  275.